package edu.bw.interceptor;

import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;
/*
* preHandle 方法
* 在handler执行前执行,如果定义多个，按配置顺序正向执行
* 如果返回false,则后续的拦截器和handler都不执行
* postHandle 方法
* 在handler执行后执行,如果定义多个，按配置顺序反向执行
* 如果handler抛异常,则后续的postHandle方法不执行
* afterCompletion 方法
* 在视图渲染完成后执行,如果定义多个，按配置顺序反向执行,前提是该拦截器preHandle方法执行了并返回true
* 无论handler是否执行成功,都执行(类似 finally )
* */
public class MyHandlerInterceptor implements HandlerInterceptor {
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        System.out.println("preHandle01...");
        return true;
    }

    @Override
    public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception {

    }

    @Override
    public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception {

    }
}
